﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 代理模式
{
    //追求者 通过中间人（代理）给女孩送礼物
    class Program
    {
        static void Main(string[] args)
        {
            SchoolMM mm = new SchoolMM();
            mm.Name = "Qin";

            Proxy p = new Proxy(mm);
            p.GiveDolls();
            p.GiveFlowers();

            Console.ReadLine();
        }
    }

    interface GiveGift
    {
        void GiveDolls();
        void GiveFlowers();
    }
    //追求者
    class Pursuit:GiveGift
    {
        SchoolMM mm;
        public Pursuit (SchoolMM smm)  //要追求哪个mm
        {
            this.mm = smm;
        }
        public void GiveDolls()
        {
            Console.WriteLine(mm.Name +":送你洋娃娃！");
        }
        public void GiveFlowers()
        {
            Console.WriteLine(mm.Name + ":送你鲜花！");
        }
    }
    //被追求者
    class SchoolMM
    {
        string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
    }
    
    //代理类 ，为追求者做事，所以要有他的引用
    class Proxy:GiveGift
    {
        Pursuit pursuit;
        public Proxy (SchoolMM mm)
        {
            pursuit = new Pursuit(mm); 
        }
        public void GiveDolls()
        {
            pursuit.GiveDolls();  //代理送东西，其实是 追求者在送东西。
        }
        public void GiveFlowers()
        {
            pursuit.GiveFlowers();
        }
    }
}
